<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>返乡防疫登记</title>
</head>
<style>
    h2 ,h1{
        text-align: center;
    }

    table {
        background: cornsilk;
        width: 450px;
        margin: 0 auto;
    }

    table, td, th {
        border: 1px solid #000000;
        border-collapse: collapse;
        border-spacing: 0;
    }
</style>
<body>
<script th:src="@{/js/jquery.js}" src="/js/jquery.js"></script>
<h1>返乡防疫登记</h1>
<form id="addform" method="post" th:action="@{/add}">
    <input name="interviewStatus" type="hidden" VALUE="0"/>
    <table>
        <tr>
            <td>姓名</td>
            <td>
                <input name="personName" id="personName" type="text"/>
            </td>
        </tr>
        <tr>
            <td>身份证</td>
            <td>
                <input name="personId" id="personId" type="text"/>
            </td>
        </tr>
        <tr>
            <td>电话</td>
            <td>
                <input id="personPhone" name="personPhone"/>
            </td>
        </tr>
        <tr>
            <td>出发城市</td>
            <td>
                <input name="sendCity" id="sendCity" type="text"/>
            </td>
        </tr>
        <tr>
            <td>返乡日期</td>
            <td>
                <input name="returnDate" id="returnDate" type="text"/>
                <span>(yyyy-MM-dd)</span>
            </td>

        </tr>
        <tr>
            <td colspan="2" align="center">
                <input type="button" id="tiJiao" value="保存">
                <input type="button" id="fanhun" value="返回">
            </td>

        </tr>
    </table>
</form>
<script>
    $(function () {
        $("#fanhun").click(function () {
            history.go(-1);
        })
        /**
         * 新增按钮点击事件
         */
        $("#tiJiao").click(function () {
            let personName = $("#personName").val();
            let personId = $("#personId").val();
            let personPhone = $("#personPhone").val();
            let sendCity = $("#sendCity").val();
            let returnDate = $("#returnDate").val();
            let reg = /[0-9]{4}-[0-9]{2}-[0-9]{2}/;
            if (personName == '') {
                alert('姓名不能为空,请重新输入')
                return;
            }
            if (personId == ''){
                alert('身份证不能为空,请重新输入')
                return;
            }
            if (personPhone == ''){
                alert('电话不能为空,请重新输入')
                return;
            }
            if (sendCity == ''){
                alert('出发城市不能为空,请重新输入')
                return;
            }
            if (returnDate == ''){
                alert('时间不能为空,请重新输入')
                return;
            }
            if (reg.exec(returnDate) == null) {
                alert("日期格式不正确!");
                return;
            }

            $.post("/add",$("#addform").serialize(),function (data) {
                if (data.code = '1000'){
                    location.href = "/"
                }
            })
        })
    })
</script>
</body>
</html>